import { ref, onMounted } from 'vue'
import { CommonOptionsApi } from '@/api/erp/commonOptions'
import { WarehouseApi } from '@/api/erp/stock/warehouse'
import { ProductApi, } from '@/api/erp/product/product'
import { SupplierApi } from '@/api/erp/purchase/supplier'
/* productCategory: 获取产品分类
productBrand: 获取产品品牌
warehouseZone: 获取仓位
productList: 产品列表
businessType: 获取业务类型
warehouse: 获取仓库
supplier: 获取供应商
 */
type typeValue = 'productCategory' | 'productBrand' | 'warehouseZone' | 'productList' | 'businessType' | 'warehouse' | 'supplier'
type OptionType = typeValue[]
const useCommonOptions = (types: OptionType = ['productCategory', 'productBrand', 'warehouseZone', 'productList', 'businessType', 'warehouse', 'supplier']) => {
  //产品分类
  const productCategory = ref([])
  //产品品牌
  const productBrand = ref([])
  //仓库
  const warehouse = ref([])
  //仓位
  const warehouseZone = ref([])
  // 产品列表
  const productList = ref([])
  //业务类型
  const businessType = ref([])
  // 供应商列表
  const supplier = ref([])
  const getProductCategory = async () => {
    CommonOptionsApi.getProductCategory().then(res => {
      productCategory.value = res

    })
  }
  const getProductBrand = async () => {
    CommonOptionsApi.getProductBrand().then(res => {
      productBrand.value = res

    })
  }
  const getWarehouseZone = async () => {
    CommonOptionsApi.getWarehouseZone().then(res => {
      warehouseZone.value = res

    })
  }
  const getProductList = async () => {
    ProductApi.getProductSimpleList().then(res => {
      productList.value = res

    })
  }
  const getBusinessType = async () => {
    CommonOptionsApi.getBusinessType().then(res => {
      businessType.value = res
    })
  }
  const getWarehouse = async () => {
    WarehouseApi.getWarehouseSimpleList().then(res => {
      warehouse.value = res
    })
  }
  const getSupplier = async () => {
    SupplierApi.getSupplierSimpleList().then(res => {
      supplier.value = res
    })
  }
  onMounted(() => {
    const map = {
      productCategory: getProductCategory,
      productBrand: getProductBrand,
      warehouseZone: getWarehouseZone,
      businessType: getBusinessType,
      warehouse: getWarehouse,
      productList: getProductList,
      supplier: getSupplier
    }
    types.forEach(item => {
      map[item]()
    })
  })
  return { productCategory, productBrand, warehouseZone, businessType, warehouse, productList, supplier }
}

export { useCommonOptions }
